package com.ymatou.iapi.livebuyer.testcase;

import com.ymatou.iapi.livebuyer.parameter.SubscribeBean;
import com.ymatou.iapi.livebuyer.parameter.UnSubscribeBean;
import com.ymatou.iapi.livebuyer.service.SubscribeCall;
import com.ymatou.iapi.livebuyer.service.UnSubscribeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Map;
/**
*取消订阅直播
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnSubscribe{
	private static UnSubscribeBean unsubscribeBean;
	private static UnSubscribeCall unsubscribeCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订阅直播");
	}

	@Before
	public void caseUp() {
		unsubscribeBean=new UnSubscribeBean();
		unsubscribeCall=new UnSubscribeCall();
	
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unsubscribeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_Subscribe_001() {
		Logger.start(true,"取消直播订阅，app，成功");
		try {
			//创建直播订阅
			SubscribeBean subscribeBean = new SubscribeBean();
			SubscribeCall subscribeCall = new SubscribeCall();

			int liveid = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null)).getId();
			int  userId=4085;	
			subscribeBean.setLiveId(liveid);
			subscribeBean.setUserId(userId);
			subscribeBean.setSource(0);
			subscribeCall.setData(subscribeBean);
			subscribeCall.callService();			
			Logger.verifyEquals("200", subscribeCall.getString("code"), "判断code");			
			Map m1=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m1.get("Status").toString()),"验证Status");
			Logger.verifyEquals(0, (Integer)m1.get("Source"),"验证Souce");
			//取消直播订阅
			unsubscribeBean.setLiveId(liveid);
			unsubscribeBean.setUserId(userId);
			unsubscribeCall.setData(unsubscribeBean);
			unsubscribeCall.callService();			
			Logger.verifyEquals("200", unsubscribeCall.getString("code"), "判断code");			
			Map m2=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(0, Integer.parseInt(m2.get("Status").toString()),"验证Status");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_Subscribe_002() {
		Logger.start(true,"取消直播订阅，成功,WXApp");
		try {
			//创建直播订阅
			SubscribeBean subscribeBean = new SubscribeBean();
			SubscribeCall subscribeCall = new SubscribeCall();

			int liveid = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null)).getId();
			int  userId=4085;
			subscribeBean.setLiveId(liveid);
			subscribeBean.setUserId(userId);
			subscribeBean.setSource(1);
			subscribeBean.setFormId("1x00087cde975f21a700252b3e761b738");
			subscribeCall.setData(subscribeBean);
			subscribeCall.callService();
			Logger.verifyEquals("200", subscribeCall.getString("code"), "判断code");
			Map m1=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m1.get("Status").toString()),"验证Status");
			Logger.verifyEquals(1, (Integer)m1.get("Source"),"验证Souce");
			//取消直播订阅
			unsubscribeBean.setLiveId(liveid);
			unsubscribeBean.setUserId(userId);
			unsubscribeCall.setData(unsubscribeBean);
			unsubscribeCall.callService();
			Logger.verifyEquals("200", unsubscribeCall.getString("code"), "判断code");
			Map m2=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(0, Integer.parseInt(m2.get("Status").toString()),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_Subscribe_003() {
		Logger.start(true,"取消直播订阅,WXApp，app");
		try {
			//创建直播订阅
			SubscribeBean subscribeBean = new SubscribeBean();
			SubscribeBean subscribeBean1 = new SubscribeBean();
			SubscribeCall subscribeCall = new SubscribeCall();

			int liveid = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null)).getId();
			int  userId=4085;
			subscribeBean.setLiveId(liveid);
			subscribeBean.setUserId(userId);
			subscribeBean.setSource(1);
			subscribeBean.setFormId("1x00087cde975f21a700252b3e761b738");
			subscribeCall.setData(subscribeBean);
			subscribeCall.callService();

			subscribeBean1.setLiveId(liveid);
			subscribeBean1.setUserId(userId);
			subscribeBean1.setSource(0);
			subscribeCall.setData(subscribeBean1);
			subscribeCall.callService();
			Logger.verifyEquals("200", subscribeCall.getString("code"), "判断code");
			Map m1=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Logger.verifyEquals(1, Integer.parseInt(m1.get("Status").toString()),"验证Status");
			//取消直播订阅
			unsubscribeBean.setLiveId(liveid);
			unsubscribeBean.setUserId(userId);
			unsubscribeCall.setData(unsubscribeBean);
			unsubscribeCall.callService();
			Logger.verifyEquals("200", unsubscribeCall.getString("code"), "判断code");
			Map m2=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(0);
			Map m3=new LiveRoomWapper().selectLiveSubscribeById(liveid,userId).get(1);
			Logger.verifyEquals(0, Integer.parseInt(m2.get("Status").toString()),"验证Status");
			Logger.verifyEquals(0, Integer.parseInt(m3.get("Status").toString()),"验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}